#include <stdio.h>
#include <string.h>
#include <stdlib.h>


int main()
{
    FILE *fd = NULL;
    long string=0;

    fd = fopen("./main.c","r");
    if(fd == NULL){
        perror("open error");
        fclose(fd);
        exit(-1);
    }
    printf("Open Success!\n");

    //将读写位置移动到文件末尾 
    if (0 > fseek(fd, 0, SEEK_END)) { 
        perror("fseek error"); 
        fclose(fd); 
        exit(-1); 
    } 

    //获取当前位置偏移量
    if(0 > (string=ftell(fd))){
        perror("获取文件偏移量失败");
        fclose(fd);
        exit(-1);
    }

    printf("main.c 文件大小为：%ld\n",string);

    if(0 > fclose(fd)){
        perror("close error");
        exit(-1);
    }

    return 0;
}